package zsrt.com.service;

import java.util.Scanner;
import zsrt.com.dao.AdminBusinessDao;
import zsrt.com.dao.ExamineeDao;
import zsrt.com.dao.impl.AdminBusinessDaoImpl;
import zsrt.com.dao.impl.ExamineeDaoImpl;

public class SvrAdmin {
	/**
	 * 业务类初始化
	 */
	private AdminBusinessDao dao = new AdminBusinessDaoImpl();
	
	/**
	 * 初始化考生对象，需要用到的时候再new
	 */
	private ExamineeDao examinee;
	
	/**
	 * 考生增加
	 */
	public void examineeAdd(Scanner scanner){
		System.err.println("输入你要增加的准考证....");
		String id = scanner.next();
		boolean result = dao.examineeGudge(id);
		if(result){
			System.out.println("准考证已经存在...无法加入...");
			return;
		}
		examinee = new ExamineeDaoImpl();
		examinee.setId(id);
		System.err.println("输入你要增加的名字...");
		examinee.setName(scanner.next());
		System.err.println("输入你要增加的年龄...");
		examinee.setAge(scanner.nextInt());
		System.err.println("输入你要增加的密码...");
		examinee.setPassword(scanner.next());
		System.err.println("输入你要增加的手机号...");
		examinee.setPhone(scanner.next());
		System.err.println("输入你要增加的省份...");
		examinee.setProvince(scanner.next());
		System.err.println("输入你要增加的城市...");
		examinee.setCity(scanner.next());
		System.err.println("输入你要增加的语文分数...");
		double chinese = scanner.nextDouble();
		examinee.setChinese(chinese);
		System.err.println("输入你要增加的数学分数...");
		double math = scanner.nextDouble();
		examinee.setMath(math);
		System.err.println("输入你要增加的英语分数...");
		double english = scanner.nextDouble();
		examinee.setEnglish(english);
		examinee.setTotal(chinese + math + english);
		
		dao.examineeAdd(examinee);
	}
	
	/**
	 * 考生删除
	 */
	public void examineeDelete(Scanner scanner){
		System.err.println("输入你要删除的准考证...");
		String id = scanner.next();
		examinee = new ExamineeDaoImpl();
		examinee.setId(id);
		boolean result = dao.examineeDelete(examinee);
		if(result){
			System.err.println("删除成功");
		}else{
			System.err.println("输入的准考证不存在,无法删除...");
		}
	}
	
	/**
	 * 考生修改
	 */
	public void examineeUpdate(Scanner scanner){
		System.err.println("输入你要修改的准考证....");
		String id = scanner.next();
		boolean result = dao.examineeGudge(id);
		if(!result){
			System.out.println("准考证不存在...无法修改...");
			return;
		}
		examinee = new ExamineeDaoImpl();
		examinee.setId(id);
		System.err.println("输入你要修改的年龄...");
		examinee.setAge(scanner.nextInt());
		System.err.println("输入你要增加的密码...");
		examinee.setPassword(scanner.next());
		System.err.println("输入你要增加的省份...");
		examinee.setProvince(scanner.next());
		System.err.println("输入你要增加的城市...");
		examinee.setCity(scanner.next());
		dao.examineeUpdate(examinee);
	}
	
	/**
	 * 考生查询
	 */
	public void examineeQuery(){
		dao.examineeQuery();
	}
	
	/**
	 * 根据考生户籍所在地查询
	 */
	public void examineeCity(Scanner scanner){
		examinee = new ExamineeDaoImpl();
		System.err.println("输入你要查询的户籍所在地...");
		examinee.setCity(scanner.next());
		dao.examineeCity( examinee);
	}
	
	/**
	 * 根据考生名字查询
	 */
	public void examineeQueryByName(Scanner scanner){
		examinee = new ExamineeDaoImpl();
		System.err.println("输入你要查询的名字...");
		examinee.setName(scanner.next());
		dao.examineeQueryByName(examinee);
	}
	
	/**
	 * 根据考生准考证查询
	 */
	public void examineeQueryById(Scanner scanner){
		examinee = new ExamineeDaoImpl();
		System.err.println("输入你要查找的准考证号...");
		examinee.setId(scanner.next());
		dao.examineeQueryById(examinee);
	}
}
